import React from 'react'

import { SearchPatternType } from '../graphql-operations'

import { RepogroupPage, RepogroupPageProps } from './RepogroupPage'
import { RepogroupMetadata } from './types'

export const python2To3Metadata: RepogroupMetadata = {
    title: 'Refactor Python 2 to 3',
    name: 'python',
    url: '/refactor-python2-to-3',
    description:
        'The examples below help you find Python 2 code that requires refactoring, and review examples of the new Python 3 syntax, across popular Python repositories.',
    examples: [
        {
            title: 'Python 3 explicit relative imports',
            description:
                'Python 3 requires you to explicitly specify package location relative to the current folder, and deprecates implicit relative reports. The search below returns usages of explicit relative imports. For example, an import with one leading dot signifies that the package resides in the current folder, and with two leading dots tells Python that the package is one directory up from the current one.',
            query: 'from \\B\\.\\w+ import \\w+',
            patternType: SearchPatternType.regexp,
        },
        {
            title: 'Python 2 style print statements',
            description: 'Find print statements with double quotes like print "Hello, World!".',
            query: 'lang:python print ":[string]"',
            patternType: SearchPatternType.structural,
        },
        {
            title: 'Python 3 style print statements',
            description:
                'Convert print statements to the print( ) function like print("Hello, World!"). These will work with both Python 2 and Python 3.',
            query: 'lang:python print(":[string]")',
            patternType: SearchPatternType.structural,
        },
        {
            title: 'Python 2 float division',
            description: `In Python 2, the division operator / rounds down the result to the nearest integer. To get a result with a floating point number,
            you need to convert the numbers to float and then perform the division. Python 3 no longer needs an explicit conversion to float by using 2 different
            operators: / for float division and // for integer division.`,
            query: 'float(:[numerator]) / float(:[denominator])',
            patternType: SearchPatternType.structural,
        },
        {
            title: 'Python 2 and Python 3 integer conversion',
            description: `Both Python 2 and 3 have built-in methods to allow you to easily convert integers to floats and floats to integers. For example,
            int(100.8) will be converted to 100.`,
            query: 'lang:python \\sint\\(-*\\d+\\)',
            patternType: SearchPatternType.regexp,
        },
    ],
    homepageDescription: 'Searches and suggestions to help migrate your code to Python 3.',
    homepageIcon:
        '',
}

export const Python2To3RepogroupPage: React.FunctionComponent<
    Omit<RepogroupPageProps, 'repogroupMetadata'>
> = props => <RepogroupPage {...props} repogroupMetadata={python2To3Metadata} />
